//
//  ProjectCell.m
//  IpadR
//
//  Created by edianzu on 2017/6/6.
//  Copyright © 2017年 ruilai. All rights reserved.
//

#import "ProjectCell.h"
#import "ChildModel.h"
@implementation ProjectCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
//        [self cretUI];
    }
    self.selectionStyle =UITableViewCellSelectionStyleNone;
    return self;
}

-(void)cretUI{
    
    
}

-(void)relayoutCellWithNum:(NSInteger)num andDic:(NSMutableDictionary*)dict{
    for (UIView *view in self.contentView.subviews) {
        [view removeFromSuperview];
    }
    self.contentView.backgroundColor = [UIColor whiteColor];
    ChildModel * model = [dict objectForKey:@"ChildName"];
    NSMutableArray * array = [NSMutableArray new];
    array = [dict objectForKey:@"Project"][num];
    //如果缺席
    if (model.IsAbsense ) {
        self.imageVIEW = [[UIImageView alloc]init];
        self.imageVIEW.image = [UIImage imageNamed:@"absenceView"];
        [self.contentView addSubview:self.imageVIEW];
        [self.imageVIEW mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.contentView.mas_centerX);
            make.size.mas_equalTo(CGSizeMake(400*AutoScaleHorizontal, 350*AutoScaleVertical));
            make.top.mas_equalTo(self.contentView.mas_top).with.offset(15*AutoScaleVertical);
            make.bottom.mas_equalTo(self.contentView.mas_bottom).with.offset(-15*AutoScaleVertical);
        }];
        
    }   else     {
     //没有缺席的时候
        //背景
        self.backView = [[UIView alloc]init];
        self.backView.layer.cornerRadius = 10;
        self.backView.layer.borderWidth = 1;
        self.backView.layer.borderColor = UIColorFromRGB(242, 242, 242).CGColor;
        [self.contentView addSubview:self.backView];
        [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.contentView.mas_top).with.offset(15*AutoScaleVertical);
            make.left.mas_equalTo(self.contentView.mas_left).with.offset(50*AutoScaleHorizontal);
            make.right.mas_equalTo(self.contentView.mas_right).with.offset(-50*AutoScaleHorizontal);
            make.bottom.mas_equalTo(self.contentView.mas_bottom).with.offset(-15*AutoScaleVertical);
            make.height.mas_equalTo(75*array.count*AutoScaleVertical);
        }];
        
        self.label = [[UILabel alloc]init];
        [self.label setTextAlignment:NSTextAlignmentCenter];
        self.label.textColor = UIColorFromRGB(136, 136, 136);
        self.label.font = [UIFont boldSystemFontOfSize:14*AutoScaleHorizontal];
        [self.backView addSubview:self.label];
        [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.backView.mas_left).with.offset(30*AutoScaleHorizontal);
            make.centerY.mas_equalTo(self.backView.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(60*AutoScaleHorizontal, 25*AutoScaleVertical));
        }];
        switch (num+1) {
            case 1:
                self.label.text = @"第一组";
                break;
            case 2:
                self.label.text = @"第二组";
                break;
            case 3:
                self.label.text = @"第三组";
                break;
            case 4:
                self.label.text = @"第四组";
                break;
            case 5:
                self.label.text = @"第五组";
                break;
            case 6:
                self.label.text = @"第六组";
                break;
            case 7:
                self.label.text = @"第七组";
                break;
            case 8:
                self.label.text = @"第八组";
                break;
            default:
                break;
        }

        
        self.lineView = [[UIView alloc]init];
        self.lineView.backgroundColor = UIColorFromRGB(242, 242, 242);
        [self.backView addSubview:self.lineView];
        [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.label.mas_right).with.offset(30*AutoScaleHorizontal);
            make.top.mas_equalTo(self.backView.mas_top);
            make.width.mas_equalTo(1*AutoScaleHorizontal);
            make.height.mas_equalTo(self.backView);
        }];
    int a = 0;
    for (NSMutableDictionary * dic in array) {
        //可点击背景
         self.tapView= [[UIView alloc]init];
        self.tapView.tag = a + 200;
        self.tapView.backgroundColor = [UIColor whiteColor];
        [self.backView addSubview:self.tapView];
        [self.tapView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.lineView.mas_right);
            make.top.mas_equalTo(self.backView.mas_top).with.offset(a*75*AutoScaleVertical);
            make.right.mas_equalTo(self.backView.mas_right);
            make.height.mas_equalTo(75*AutoScaleVertical);
        }];
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        [self.tapView addGestureRecognizer:tap];
        //项目图片
        self.imaV = [[UIImageView alloc]init];
        NSString * proName = [NSString stringWithFormat:@"project-%@",[dic objectForKey:@"proNum"]];
        self.imaV.image = [UIImage imageNamed:proName];
        [self.tapView addSubview:self.imaV];
        [self.imaV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.tapView.mas_left).with.offset(30*AutoScaleHorizontal);
            make.centerY.mas_equalTo(self.tapView.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(45*AutoScaleHorizontal, 45*AutoScaleVertical));
        }];
        //项目名
        self.lab = [[UILabel alloc]init];
//        [lab setTextAlignment:NSTextAlignmentCenter];
        self.lab.textColor = UIColorFromRGB(88, 88, 88);
        self.lab.font = [UIFont boldSystemFontOfSize:14*AutoScaleHorizontal];
        self.lab.text = [dic objectForKey:@"proName"];
        [self.tapView addSubview:self.lab];
        [self.lab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.imaV.mas_right).with.offset(30*AutoScaleHorizontal);
            make.centerY.mas_equalTo(self.imaV.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(100*AutoScaleHorizontal, 20*AutoScaleVertical));
        }];
        //下方横线
        self.lview = [[UIView alloc]init];
        self.lview.backgroundColor = UIColorFromRGB(242, 242, 242);
        [self.tapView addSubview:self.lview];
        [self.lview mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.mas_equalTo(self.tapView);
            make.height.mas_equalTo(1*AutoScaleVertical);
        }];
        
        //箭头
        UIImageView * arrowView = [[UIImageView alloc]init];
        arrowView.image = [UIImage imageNamed:@"arrowView"];
        [self.tapView addSubview:arrowView];
        [arrowView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.tapView.mas_right).with.offset(-20*AutoScaleHorizontal);
            make.centerY.mas_equalTo(self.tapView.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(10*AutoScaleHorizontal, 10*AutoScaleVertical));
        }];
        //项目数值///////////////////////////////////////////////////////////////////////////////////
        UILabel * scoreLabel = [[UILabel alloc]init];
        scoreLabel.font = [UIFont systemFontOfSize:14*AutoScaleHorizontal];
        [scoreLabel setTextAlignment:NSTextAlignmentRight];
        [self.tapView addSubview:scoreLabel];
        [scoreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(arrowView.mas_left).with.offset(-5*AutoScaleHorizontal);
            make.centerY.mas_equalTo(self.tapView.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(115*AutoScaleHorizontal, 30*AutoScaleVertical));
        }];
        switch ([[dic objectForKey:@"proNum"] integerValue]) {
            case 1:
                if (model.Height !=nil) {
                    scoreLabel.text =[NSString stringWithFormat:@"%@cm",@([model.Height floatValue])];
                    scoreLabel.textColor = UIColorFromRGB(88, 88, 88);
                }else{
                    scoreLabel.text =@"未测试";
                    scoreLabel.textColor = [UIColor redColor];
                }
                break;
            case 2:
                if (model.Weight !=nil) {
                    scoreLabel.text =[NSString stringWithFormat:@"%@kg",@([model.Weight floatValue])];
                    scoreLabel.textColor = UIColorFromRGB(88, 88, 88);
                }else{
                    scoreLabel.text =@"未测试";
                    scoreLabel.textColor = [UIColor redColor];
                }
                break;
            case 3:
                if (model.IsMentalShuttleRun) {
                    scoreLabel.text =@"心理发展指数";
                    scoreLabel.textColor = [UIColor redColor];
                }else if (model.IsMotorShuttleRun){
                    scoreLabel.text =@"动作发展指数";
                    scoreLabel.textColor = [UIColor redColor];
                }else{
                    if (model.ShuttleRun !=nil) {
                        scoreLabel.text =[NSString stringWithFormat:@"%@s",@([model.ShuttleRun floatValue])];
                        scoreLabel.textColor = UIColorFromRGB(88, 88, 88);
                    }else{
                        scoreLabel.text =@"未测试";
                        scoreLabel.textColor = [UIColor redColor];
                    }
                }
                break;
            case 4:
                if (model.IsMentalSitReach) {
                    scoreLabel.text =@"心理发展指数";
                    scoreLabel.textColor = [UIColor redColor];
                }else if (model.IsMotorSitReach){
                    scoreLabel.text =@"动作发展指数";
                    scoreLabel.textColor = [UIColor redColor];
                }else{
                    if (model.SitReach !=nil) {
                        scoreLabel.text =[NSString stringWithFormat:@"%@cm",@([model.SitReach floatValue])];
                        scoreLabel.textColor = UIColorFromRGB(88, 88, 88);
                    }else{
                        scoreLabel.text =@"未测试";
                        scoreLabel.textColor = [UIColor redColor];
                    }
                }
                break;
            case 5:
                if (model.IsMentalBroadJump) {
                    scoreLabel.text =@"心理发展指数";
                    scoreLabel.textColor = [UIColor redColor];
                }else if (model.IsMotorBroadJump){
                    scoreLabel.text =@"动作发展指数";
                    scoreLabel.textColor = [UIColor redColor];
                }else{
                    if (model.BroadJump !=nil) {
                        scoreLabel.text =[NSString stringWithFormat:@"%@cm",@([model.BroadJump floatValue])];
                        scoreLabel.textColor = UIColorFromRGB(88, 88, 88);
                    }else{
                        scoreLabel.text =@"未测试";
                        scoreLabel.textColor = [UIColor redColor];
                    }
                }
                break;
            case 6:
                if (model.IsMentalDoubleJump) {
                    scoreLabel.text =@"心理发展指数";
                    scoreLabel.textColor = [UIColor redColor];
                }else if (model.IsMotorDoubleJump){
                    scoreLabel.text =@"动作发展指数";
                    scoreLabel.textColor = [UIColor redColor];
                }else{
                    if (model.DoubleJump !=nil) {
                        scoreLabel.text =[NSString stringWithFormat:@"%@s",@([model.DoubleJump floatValue])];
                        scoreLabel.textColor = UIColorFromRGB(88, 88, 88);
                    }else{
                        scoreLabel.text =@"未测试";
                        scoreLabel.textColor = [UIColor redColor];
                    }
                }
                break;
            case 7:
                if (model.IsMentalThrow) {
                    scoreLabel.text =@"心理发展指数";
                    scoreLabel.textColor = [UIColor redColor];
                }else if (model.IsMotorThrow){
                    scoreLabel.text =@"动作发展指数";
                    scoreLabel.textColor = [UIColor redColor];
                }else{
                    if (model.Throw !=nil) {
                        scoreLabel.text =[NSString stringWithFormat:@"%@m",@([model.Throw floatValue])];
                        scoreLabel.textColor = UIColorFromRGB(88, 88, 88);
                    }else{
                        scoreLabel.text =@"未测试";
                        scoreLabel.textColor = [UIColor redColor];
                    }
                }
                break;
            case 8:
                if (model.IsMentalBalance) {
                    scoreLabel.text =@"心理发展指数";
                    scoreLabel.textColor = [UIColor redColor];
                }else if (model.IsMotorBalance){
                    scoreLabel.text =@"动作发展指数";
                    scoreLabel.textColor = [UIColor redColor];
                }else{
                    if (model.Balance !=nil) {
                        scoreLabel.text =[NSString stringWithFormat:@"%@s",@([model.Balance floatValue])];
                        scoreLabel.textColor = UIColorFromRGB(88, 88, 88);
                    }else{
                        scoreLabel.text =@"未测试";
                        scoreLabel.textColor = [UIColor redColor];
                    }
                }
                break;
            default:
                break;
        }
        
        
        
        a++;
        if (a == array.count) {
            break;
        }
    }
    }
    
}

- (void)tapAction:(UITapGestureRecognizer *)tap{
    _action(tap.view.tag - 200);
//    NSLog(@"aCTION的INTEGERRRR   %d",tap.view.tag - 200);
}
@end


















